package sel.me.spring.boot159.web.exception;


import org.apache.commons.lang3.StringUtils;

public class UnifyRuntimeStrException extends RuntimeException {

	private UnifyStrErrorCode errorCode;

	public UnifyRuntimeStrException(UnifyStrErrorCode errorCode) {
		this.errorCode = errorCode;
	}

	public UnifyRuntimeStrException(UnifyStrErrorCode errorCode, String message) {
		super(message);
		this.errorCode = errorCode;
	}

	public UnifyRuntimeStrException(UnifyStrErrorCode errorCode, String message, Throwable cause) {
		super(message, cause);
		this.errorCode = errorCode;
	}

	public UnifyRuntimeStrException(UnifyStrErrorCode errorCode, Throwable cause) {
		super(cause);
		this.errorCode = errorCode;
	}

	public UnifyStrErrorCode getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(UnifyStrErrorCode errorCode) {
		this.errorCode = errorCode;
	}

	public String getMessage() {
		if (errorCode == null)
			return super.getMessage();
		if (StringUtils.isNotBlank(super.getMessage()))
			return (new StringBuilder()).append(super.getMessage()).append(" | ").append(errorCode.getErrorCode())
					.append(":").append(errorCode.getErrorMsg()).toString();
		else
			return (new StringBuilder()).append(errorCode.getErrorCode()).append(":").append(errorCode.getErrorMsg())
					.toString();
	}
}